package unittest;

import static org.junit.Assert.assertEquals;

import org.junit.Test;

import treeedit.BZAddressParser;
import treeedit.TedAlgorithm;
import treeedit.Tree;

public class TedAlgorithmTest_kr {

	@Test
	public void testKr() {
		int[] kr_expect = new int[] { 0, 3, 5, 6 };

		// =============Initialize================
		Tree tree1 = createDumpT1();
		tree1.init();
		int[] l1 = TedAlgorithm.lmld(tree1);

		// =========Get Key root array from Tree1=================
		int[] kr_result = TedAlgorithm.getKeyRoot(l1, tree1.getLeavesSize());

		// ==========TEST==============
		assertEquals("Result", kr_expect[0], kr_result[0]);
		assertEquals("Result", kr_expect[1], kr_result[1]);
		assertEquals("Result", kr_expect[2], kr_result[2]);
		assertEquals("Result", kr_expect[3], kr_result[3]);
	}
	
	static Tree createDumpT1() {
		Tree f = new Tree("f");
		Tree d = f.addChild(new Tree("d"));
		d.addChild(new Tree("a"));
		Tree c = d.addChild(new Tree("c"));
		c.addChild(new Tree("b"));
		f.addChild(new Tree("e"));
		return f;
	}

}
